var oContent=document.getElementById("content");
var oTravel_bg=document.getElementById("step_into_r");
var oSt=document.getElementById("s_h2");
var oSp=document.getElementById("s_p");
var oBgLeft=document.getElementById("bgLeft");
var oMh=document.getElementById("m_h2");
var oMp=document.getElementById("m_p");
var oFlash1_h4=document.getElementById("flash1_h4");
var oFlash2_h4=document.getElementById("flash2_h4");
var oFlash1_h2=document.getElementById("flash1_h2");
var oFlash2_h2=document.getElementById("flash2_h2");
var oFlash1_button=document.getElementById("flash1_button");
var oFlash2_button=document.getElementById("flash2_button");
var oDesign_h2=document.getElementById("design_h2");
var oDesign_p=document.getElementById("design_p");
var oPhoto1=document.getElementById("photo1");
var oPhoto2=document.getElementById("photo2");
var oPhoto3=document.getElementById("photo3");
var oPhoto4=document.getElementById("photo4");
var oTouch_h2=document.getElementById("touch_h2");
var oTouch_p=document.getElementById("touch_p");
var oCommunity_h2=document.getElementById("community_h2");
var oCommunity_p=document.getElementById("community_p");
var oSection_h2=document.getElementById("section_h2");
var oSection_p=document.getElementById("section_p");
var oObjectCarousel=document.getElementById("objectCarousel");
var oFlash1=document.getElementById("flash_1");
var oFlash2=document.getElementById("flash_2");
var oFlash3=document.getElementById("flash_3");
(function(){
    oContent.style.opacity=1;
    setTimeout(function(){
        oContent.style.top=0;
        oContent.style.transition="top 1s";
    },10);
})();
window.onscroll=function(){
    //console.log(document.body.scrollTop);  //获取滚动条的位置
    if(document.body.scrollTop>900){
        oTravel_bg.style.opacity=1;
        setTimeout(function(){
            oTravel_bg.style.top=140+"px";
            oTravel_bg.style.transition="top 1s";
        },10);
    }
    if(document.body.scrollTop>1900){
        oSt.style.opacity=1;
        setTimeout(function(){
            oSt.style.left=0;
            oSt.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>2000){
        oSp.style.opacity=1;
        setTimeout(function(){
            oSp.style.top=100+"px";
            oSp.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>2500){
        oBgLeft.style.opacity=1;
        setTimeout(function(){
            oBgLeft.style.left=0;
            oBgLeft.style.top=0;
            oBgLeft.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>2700){
        oMh.style.opacity=1;
        setTimeout(function(){
            oMh.style.top=0;
            oMh.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>2800){
        oMp.style.opacity=1;
        setTimeout(function(){
            oMp.style.top=0;
            oMp.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>3700){
        oFlash1_h4.style.opacity=1;
        setTimeout(function(){
            oFlash1_h4.style.top=30+"%";
            oFlash1_h4.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>3800){
        oFlash1_h2.style.opacity=1;
        oFlash1_button.style.opacity=1;
        setTimeout(function(){
            oFlash1_h2.style.top=35+"%";
            oFlash1_button.style.top=40+"%";
            oFlash1_button.style.transition="all 1s";
            oFlash1_h2.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>4500){
        oFlash2_h4.style.opacity=1;
        setTimeout(function(){
            oFlash2_h4.style.top=30+"%";
            oFlash2_h4.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>4600){
        oFlash2_h2.style.opacity=1;
        oFlash2_button.style.opacity=1;
        setTimeout(function(){
            oFlash2_h2.style.top=35+"%";
            oFlash2_button.style.top=40+"%";
            oFlash2_button.style.transition="all 1s";
            oFlash2_h2.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>4900){
        oDesign_h2.style.opacity=1;
        setTimeout(function(){
            oDesign_h2.style.top=0;
            oDesign_h2.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>5000){
        oDesign_p.style.opacity=1;
        setTimeout(function(){
            oDesign_p.style.top=0;
            oDesign_p.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>5600){
        oPhoto1.style.opacity=1;
        setTimeout(function(){
            oPhoto1.style.top=0;
            oPhoto2.style.top=0;
        },10);
    }
    if(document.body.scrollTop>6000){
        oPhoto3.style.opacity=1;
        setTimeout(function(){
            oPhoto3.style.top=0;
            oPhoto4.style.top=0;
        },10);
    }
    if(document.body.scrollTop>6800){
        oTouch_h2.style.opacity=1;
        setTimeout(function(){
            oTouch_h2.style.top=0;
            oTouch_h2.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>6900){
        oTouch_p.style.opacity=1;
        setTimeout(function(){
            oTouch_p.style.top=0;
            oTouch_p.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>7350){
        oCommunity_h2.style.opacity=1;
        setTimeout(function(){
            oCommunity_h2.style.top=0;
            oCommunity_h2.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>7450){
        oCommunity_p.style.opacity=1;
        setTimeout(function(){
            oCommunity_p.style.top=0;
            oCommunity_p.style.transition="all 1s";
        },10);
    }
    if(document.body.scrollTop>8058) {
        oSection_h2.style.opacity = 1;
        setTimeout(function () {
            oSection_h2.style.lineHeight = 211 + "px";
            oSection_h2.style.transition = "all 1s";
        }, 10);
    }
    if(document.body.scrollTop>8158){
        oSection_p.style.opacity=1;
        setTimeout(function(){
            oSection_p.style.paddingTop=120+"px";
            oSection_p.style.transition="all 1s";
        },10);
    }
};

//轮播
function closeCarousel(){
    oObjectCarousel.style.display="none";  //关闭轮播窗口
}
var oArr=["./../img/features-2.jpg","./../img/features-3.jpg","./../img/features-xbox-controller.jpg","./../img/features-oculus-remote.jpg"];
var oArr1=["./../img/features-xbox-controller.jpg","./../img/features-oculus-remote.jpg","./../img/features-2.jpg","./../img/features-3.jpg"];
var oArr_t=["集成虚拟现实音频","为VR设计的传感器","好游戏需要好手柄","远程直观的探索"];
var oArr_t1=["好游戏需要好手柄","远程直观的探索","集成虚拟现实音频","为VR设计的传感器"];
var obj1=document.getElementById("obj1");
var obj2=document.getElementById("obj2");
var obj3=document.getElementById("obj3");
var ott1=document.getElementById("p_border0");
var ott2=document.getElementById("p_border1");
var ott3=document.getElementById("p_border2");
var i=0;
var t=0;
function moveLeft(){
    newTime= new Date().getTime();
    if(newTime-t<=500){return;}
    t=newTime;
    obj3.src=oArr1[i];
    ott3.innerHTML=oArr_t1[i];
    obj1.style.left=981+"px";
    ott1.style.left=981+"px";
    obj3.style.left=0;
    ott3.style.left=0;
    obj1.style.transition="left 1s";
    ott1.style.transition="left 1s";
    obj3.style.transition="left 1s";
    ott3.style.transition="left 1s";
    setTimeout(changeImage,1000)
}
function changeImage(){
    obj1.src=obj3.src;
    ott1.innerHTML=ott3.innerHTML;
    obj1.style.left=0;
    ott1.style.left=0;
    obj1.style.transition="all 0s";
    ott1.style.transition="all 0s";
    obj3.style.left=-981+"px";
    ott3.style.left=-981+"px";
    obj3.style.transition="all 0s";
    ott3.style.transition="all 0s";
    i--;
    console.log(i);
    if(i<0){
        i=3;
    }
}
function moveRight(){
    newTime= new Date().getTime();
    if(newTime-t<=500){return;}
    t=newTime;
    obj2.src=oArr[i];
    ott2.innerHTML=oArr_t[i];
    obj1.style.left=-981+"px";
    ott1.style.left=-981+"px";
    obj2.style.left=0;
    ott2.style.left=0;
    obj1.style.transition="left 1s";
    ott1.style.transition="left 1s";
    obj2.style.transition="left 1s";
    ott2.style.transition="left 1s";
    setTimeout(changeIma,1000)
}
function changeIma(){
    obj1.src=obj2.src;
    ott1.innerHTML=ott2.innerHTML;
    obj1.style.left=0;
    ott1.style.left=0;
    obj1.style.transition="all 0s";
    ott1.style.transition="all 0s";
    obj2.style.left=981+"px";
    ott2.style.left=981+"px";
    obj2.style.transition="all 0s";
    ott2.style.transition="all 0s";
    i++;
    console.log(i);
    if(i>3){
        i=0;
    }
}


function playCarousel_1(){
    oObjectCarousel.style.display="block";
    i=1;
    //moveLeft();
    setTimeout(moveLeft,100)
  }
function playCarousel_2(){
    oObjectCarousel.style.display="block";
    i=2;
    //moveLeft();
    setTimeout(moveLeft,100)
}
function playCarousel_3(){
    oObjectCarousel.style.display="block";
    i=3;
    setTimeout(moveLeft,100)

}
function playCarousel_4(){
    oObjectCarousel.style.display="block";
    i=0;
    //moveLeft();
    setTimeout(moveLeft,100)
}


var oBuyrift=document.getElementById('buy1');
oBuyrift.onclick=function(){
    var http=new XMLHttpRequest();
    var data;
    http.open('get','/addCart.do?p_id='+this.id[this.id.length-1]);
    console.log(this.id[this.id.length-1]);
    http.send(null);
    http.onreadystatechange=function(){
        if(http.readyState==4&&http.status==200){
        }
    }
};

//flash视频

function closeFlash(){
    oFlash1.style.display="none";
    oFlash2.style.display="none";
    oFlash3.style.display="none";
    document.body.style.overflow="inherit";
}

function openFlash_1(){
    oFlash1.style.display="block";
    document.body.style.overflow="hidden";
}
function openFlash_2(){
    oFlash2.style.display="block";
    document.body.style.overflow="hidden";
}
function openFlash_3(){
    oFlash3.style.display="block";
    document.body.style.overflow="hidden";
}